package com.demo.springBoot2.quartz.quartz.scheduler;

import com.demo.springBoot2.quartz.quartz.job.CallMyGirlFriendsJob;
import com.demo.springBoot2.quartz.quartz.trigger.SimpleGetTrigger;
import lombok.val;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * 任务调度器工具
 * */
public class SchedulerUtil {
    public static void addJob() throws SchedulerException {
        // 创建一个第调度器工厂
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = schedulerFactory.getScheduler();
        // 创建作业案例 JobBuilder
        val job = JobBuilder.newJob(CallMyGirlFriendsJob.class)
                .withIdentity("job1", "group1")
                .build();
        // 创建一个触发器
        Trigger trigger = SimpleGetTrigger.createTrigger();
        // 添加作业和触发器 绑定
        scheduler.scheduleJob(job, trigger);
        // 启动调度器
        scheduler.start();
    }
}
